package com.gin.supermarket_inventory_system.inventory.dto.form.receipt;

import com.gin.supermarket_inventory_system.inventory.entity.InventoryReceiptPo;
import com.gin.supermarket_inventory_system.inventory.enums.InventoryReceiptType;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import lombok.Getter;
import lombok.Setter;
import org.springframework.beans.BeanUtils;

import java.util.List;

/**
 * 单据表单
 * @since : 2023/10/11 14:55
 * @author : ginstone
 * @version : v1.0.0
 **/
@Getter
@Setter
@Schema(description = "表单对象:单据表单")
public class ReceiptForm {
    @Schema(description = "备注")
    String remark;

    @Schema(description = "单据详情")
    @NotEmpty
    @Valid
    List<ReceiptFormDetail> details;

    public InventoryReceiptPo toPo(InventoryReceiptType type) {
        final InventoryReceiptPo po = new InventoryReceiptPo();
        BeanUtils.copyProperties(this, po);
        po.setType(type);
        return po;
    }
}